
package com.city.parking.util;

import java.util.Set;

import com.city.parking.ParkingApp;
import com.city.parking.R;

import android.content.Context;
import android.content.SharedPreferences;


public class SharePrefUtil {
    private static final String LONGITUDE_KEY = "last_longitude";
    private static final String LATITUDE_KEY = "last_latitude";
    private static final String PHONE_KEY = "phone";
    private static final String USR_ID_KEY = "usr_id";
    private static final String CAR_ID_KEY = "car_id";
    private static final String HISTORY_KEY = "history";
    private static final String SEARCH_RADIUS_KEY = "search_radius";
    private static final String INDOOR_START_KEY = "indoor_start";
    private static final String INDOOR_END_KEY = "indoor_end";
    private static final String FOOR_KEY = "floor";
    private static final String BUILD_KEY = "build";
    private static final String MAP_TYPE_KEY = "map_type";
    
    private static String AUTO_UPGRADE_KEY = "";

    private static Context mContext;
    private static SharedPreferences mPrf;
    private static SharedPreferences mSettingPrf;

    public static void init(Context ctx) {
        mContext = ctx;
        mPrf = mContext.getSharedPreferences(ctx.getPackageName(), Context.MODE_PRIVATE);
        mSettingPrf = mContext.getSharedPreferences(ctx.getPackageName()+"_preferences", Context.MODE_PRIVATE);
        
        AUTO_UPGRADE_KEY = mContext.getResources().getString(R.string.pref_auto_upgrage_wifi_key);
    }
    
    public static boolean getAutoUpdateInWifi() {
    	return mSettingPrf.getBoolean(AUTO_UPGRADE_KEY, true);
    }

    public static int getSearchRadius(int dft) {
        return mPrf.getInt(SEARCH_RADIUS_KEY, dft);
    }

    public static void setSearchRadius(int radius) {
        mPrf.edit().putInt(SEARCH_RADIUS_KEY, radius).commit();
    }

    public static float getLastLongitude() {
        return mPrf.getFloat(LONGITUDE_KEY, -1);
    }
    
    public static void setLastLongitude(float lng) {
        mPrf.edit().putFloat(LONGITUDE_KEY, lng).commit();
    }
    
    public static float getLastLatitude() {
        return mPrf.getFloat(LATITUDE_KEY, -1);
    }
    
    public static void setLastLatitude(float lat) {
        mPrf.edit().putFloat(LATITUDE_KEY, lat).commit();
    }

    public static String getUsrId() {
        return mPrf.getString(USR_ID_KEY, "-1");
    }
    
    public static void setUsrId(String id) {
        mPrf.edit().putString(USR_ID_KEY, id).commit();
    }
    
    public static int getMapType() {
        return mPrf.getInt(MAP_TYPE_KEY, ParkingApp.BAIDU_MAP);
    }
    
    public static void setMapType(int type) {
        mPrf.edit().putInt(MAP_TYPE_KEY, type).commit();
    }

    public static String getPhone() {
        return mPrf.getString(PHONE_KEY, null);
    }

    public static void setPhone(String phone) {
        mPrf.edit().putString(PHONE_KEY, phone).commit();
    }
    
    public static String getCarId() {
        return mPrf.getString(CAR_ID_KEY, null);
    }
    
    public static void setCarId(String id) {
        mPrf.edit().putString(CAR_ID_KEY, id).commit();
    }
    
    public static int getIndoorStart() {
        return mPrf.getInt(INDOOR_START_KEY, -1);
    }
    
    public static void setIndoorStart(int start) {
        mPrf.edit().putInt(INDOOR_START_KEY, start).commit();
    }
    
    public static int getIndoorEnd() {
        return mPrf.getInt(INDOOR_END_KEY, -1);
    }
    
    public static void setIndoorEnd(int start) {
        mPrf.edit().putInt(INDOOR_END_KEY, start).commit();
    }

    public static int getFloor() {
        return mPrf.getInt(FOOR_KEY, 0);
    }

    public static void setFloor(int f) {
        mPrf.edit().putInt(FOOR_KEY, f).commit();
    }    

    public static int getBuild() {
        return mPrf.getInt(BUILD_KEY, 0);
    }

    public static void setBuild(int f) {
        mPrf.edit().putInt(BUILD_KEY, f).commit();
    }
    
    public static String getSearchHistory() {
        return mPrf.getString(HISTORY_KEY, null);
    }
    
    public static void setSearchHistory(String set) {
        mPrf.edit().putString(HISTORY_KEY, set).commit();
    }

    public static void logout() {
    	setUsrId("");
    	setPhone("");
    	setCarId("");
    }
}
